package zhangcy.day0109.qingyoutravel.dao.impl;


import zhangcy.day0109.qingyoutravel.dao.ScenicSpotDao;
import zhangcy.day0109.qingyoutravel.po.ScenicSpot;
import zhangcy.day0109.qingyoutravel.utils.BaseDao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 *
 */
public class ScenicSpotDaoImpl extends BaseDao implements ScenicSpotDao {
    @Override
    public List<ScenicSpot> queryAllScenicSpots() {
        List<ScenicSpot> scenicSpots = new ArrayList<>();
        ScenicSpot scenicSpot = null;
        StringBuffer sql = new StringBuffer();
        sql.append(" SELECT SS_ID, SS_NAME, SS_DURATION, SS_CONTENT FROM SCENIC_SPOT ");
        rs = super.executeQuery(sql.toString());
        try {
            while (rs.next()){
                scenicSpot = new ScenicSpot(rs.getInt("SS_ID"), rs.getString("SS_NAME"),
                            rs.getString("SS_DURATION"), rs.getString("SS_CONTENT"));
                scenicSpots.add(scenicSpot);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }finally {
            super.closeAll(rs, pstmt, conn);
        }
        return scenicSpots;
    }
}
